import request from '@/utils/request'

export const getChannelListAPI = () =>
  request({
    url: '/v1_0/channels'
  })

export const loginAPI = ({ mobile, code }) => request({
  url: '/v1_0/authorizations',
  method: 'POST',
  data: {
    mobile,
    code
  }
})
// 获取用户频道列表
export const getUesrChannelListAPI = () => request({
  url: '/v1_0/user/channels'
  // headers: {
  //   Authorization: `Bearer ${getToken()}`
  // }
})
// 获取文章列表
export const articlesListAPI = ({ channel_id, timestamp = new Date() }) =>
  request({
    url: '/v1_0/articles',
    // headers: {
    //   Authorization: `Bearer ${getToken()}`
    // },
    params: {
      channel_id,
      timestamp
    }

  })
  // 反馈不感兴趣文章
export const dislikeArticleAPI = (artId) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  // headers: {
  //   Authorization: `Bearer ${getToken()}`
  // },
  data: {
    target: artId
  }
})
// 举报文章
export const reportArticlesAPI = ({ target, type }) =>
  request({
    url: '/v1_0/article/reports',
    method: 'POST',
    // headers: {
    //   Authorization: `Bearer ${getToken()}`
    // },
    data: {
      target: target,
      type: type,
      remark: '就是其他问题'
    }
  })
  // 更新数据
export const setuserchannelAPI = (channelsArray) =>
  request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channelsArray
    }
  })
  // 删除频道
export const removechannelAPI = (channelid) =>
  request({
    url: `/v1_0/user/channels/${channelid}`,
    method: 'DELETE'
  })
  // 获取搜索建议
export const suggestListAPI = (keyword) =>
  request({
    url: '/v1_0/suggestion',
    method: 'GET',
    params: {
      q: keyword
    }
  })
  // 获取搜索列表
export const searchResultAPI = ({ keyword, page = 1, per_page = 10 }) =>
  request({
    url: '/v1_0/search',
    method: 'GET',
    params: {
      q: keyword,
      page: page,
      per_page: per_page

    }
  })
// 获取个人资料
export const getUserInfoAPI = () =>
  request({
    url: '/v1_0/user',
    method: 'GET'
  })
// 获取用户头像信息
export const getUserSelfInfoAPI = () =>
  request({
    url: '/v1_0/user/profile',
    method: 'GET'
  })

// 更换用户头像
export const changeImageAPI = (fd) =>
  request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: fd
  })
  // 获取文章详情
export const getAriticleMoreAPI = (id) =>
  request({
    url: `/v1_0/articles/${id}`
  })
  // 关注用户
export const followingsAPI = (userid) =>
  request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: userid
    }
  })
  // 取消关注用户
export const unfollowingsAPI = (userid) =>
  request({
    url: `/v1_0/user/followings/${userid}`,
    method: 'DELETE'
  })
  // 点赞接口
export const isLikeAPI = (artid) =>
  request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: artid
    }
  })

// 取赞接口
export const unisLikeAPI = (artid) =>
  request({
    url: `/v1_0/article/likings/${artid}`,
    method: 'DELETE'
  })
  // 获取评论接口
export const getCommnentAPI = ({ artid, offset = null, limit = null }) =>
  request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artid,
      offset,
      limit
    }
  })

// 评论取消点赞
export const unisLikecommentAPI = (comid) =>
  request({
    url: `/v1_0/comment/likings/${comid}`,
    method: 'DELETE'
  })

// 评论点赞
export const isLikecommentAPI = (comid) =>
  request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comid
    }
  })
  // 更新用户接口
export const updataUserInfo = ({ name, birthday }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      name,
      birthday
    }
  })
}
